<?php

/**
 * Created by PhpStorm.
 * User: LiuJie
 * Date: 2018/7/19
 * Time: 14:33
 */
namespace App\Http\Models;
use Illuminate\Database\Eloquent\Model;
use App\Http\Models\User;

class Post extends Model
{
	protected $table = 'posts';
//	设置无黑名单字段
	protected $guarded = ['id'];

	public function user(){
		return $this->belongsTo('App\Http\Models\User','user_id','id');
	}

//	文章的评论及评论的作者
	public function comments(){
		return $this->hasMany('App\Http\Models\Comment','post_id','id')->with(
			['user'=>function($query){
				return $query->select('id','name');
			}]
		);
	}

	public function zans (  )
	{
		return $this->hasMany('App\Http\Models\Zan','post_id','id');
	}
}